package org.urchr.beorganized.dao.tables;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="tags")
public class Tag implements Comparable<Tag>, Serializable{
	private static final long serialVersionUID = 2335191992729156328L;
	private int id;
	private String name;
	private Note note;
	
	public void setId(int id) {
		this.id = id;
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column
	public String getName() {
		return name;
	}

	public void setNote(Note note) {
		this.note = note;
	}

	
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="id_note")
	public Note getNote() {
		return note;
	}

	public int compareTo(Tag o) {
//		System.out.println("compare tags: "+getName()+" with "+(o!=null?o.getName():"null"));
		if(o!=null && getName()!=null)
			return getName().compareTo(o.getName());
		return 0;
	}

}
